<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tblname
 *
 * @author chema_000
 */
class Admin_Models_tblApps extends Libs_Model{
    protected $queryUnit;

    public function __construct() {
        parent::__construct();
        $this->queryUnit = new Libs_QueryUnit();
    }

    private $id;
    private $title;
    private $images;
    private $category_id;
    private $description;
    private $point;
    private $status;
    private $updatetime;
    private $version;
    private $requirement;
    private $size;
    private $link;
    private $rate;
    private $view;
    public function getView() {
        return $this->view;
    }

    public function setView($view) {
        $this->view = $view;
    }

        public function getId() {
        return $this->id;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getImages() {
        return $this->images;
    }

    public function getCategory_id() {
        return $this->category_id;
    }

    public function getDescription() {
        return $this->description;
    }

    public function getPoint() {
        return $this->point;
    }

    public function getStatus() {
        return $this->status;
    }

    public function getUpdatetime() {
        return $this->updatetime;
    }

    public function getVersion() {
        return $this->version;
    }

    public function getRequirement() {
        return $this->requirement;
    }

    public function getSize() {
        return $this->size;
    }

    public function getLink() {
        return $this->link;
    }

    public function getRate() {
        return $this->rate;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setTitle($title) {
        $this->title = $title;
    }

    public function setImages($images) {
        $this->images = $images;
    }

    public function setCategory_id($category_id) {
        $this->category_id = $category_id;
    }

    public function setDescription($description) {
        $this->description = $description;
    }

    public function setPoint($point) {
        $this->point = $point;
    }

    public function setStatus($status) {
        $this->status = $status;
    }

    public function setUpdatetime($updatetime) {
        $this->updatetime = $updatetime;
    }

    public function setVersion($version) {
        $this->version = $version;
    }

    public function setRequirement($requirement) {
        $this->requirement = $requirement;
    }

    public function setSize($size) {
        $this->size = $size;
    }

    public function setLink($link) {
        $this->link = $link;
    }

    public function setRate($rate) {
        $this->rate = $rate;
    }

        /**
     * @param mixed $category_id
     */
    
    ///////////////////////////////////////
    
    //////////////////////////////////////

    protected function setCustomerValue($row, $isKey = TRUE) {
        $app = new Admin_Models_tblApps();
        if ($isKey) {
            $app->setId($row['id']);
        }
        $app->setCategory_id($row['category_id']);
        $app->setDescription($row['description']);
        $app->setTitle($row['title']);
        $app->setUpdatetime($row['updatetime']);
        $app->setPoint($row['point']);
        $app->setStatus($row['status']);
        $app->setImages($row['images']);
        $app->setLink($row['link']);
        $app->setRequirement($row['requirement']);
        $app->setSize($row['size']);
        $app->setVersion($row['version']);
        $app->setView($row['view']);
        return $app;
    }

    protected function getColumnAndValue(Admin_Models_tblApps $app, $isKey = FALSE) {
        $arr_data = array();
        if ($isKey) {
            $arr_data['id'] = $app->getId();
        }
        $arr_data['title'] = $app->getTitle();
        $arr_data['images'] = $app->getImages();
        $arr_data['updatetime'] = $app->getUpdatetime();
        $arr_data['point'] = $app->getPoint();
        $arr_data['status'] = $app->getStatus();
        $arr_data['description'] = $app->getDescription();
        $arr_data['category_id'] = $app->getCategory_id();
        $arr_data['link'] = $app->getLink();
        $arr_data['requirement'] = $app->getRequirement();
        $arr_data['size'] = $app->getSize();
        $arr_data['version'] = $app->getVersion();
        $arr_data['view'] = $app->getView();
        $arr_data['rate'] = $app->getRate();
        return $arr_data;
    }
    
    /////////////////////////////////
    public function getAllApp() {
        $listApp = array();
        $execute = $this->queryUnit->getSelect('tbl_apps', NULL, 'updatetime DESC');
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listApp[] = $this->setCustomerValue($row);
            }
        }
        return $listApp;
    }
    ///////////////////////////////////
    public function getSearch($Appname) {
        $listApp = array();

        $execute = $this->queryUnit->getSelect('tbl_apps', "title Like '%" . $Appname . "%'");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listApp[] = $this->setCustomerValue($row);
            }
        }
        return $listApp;
    }
    //////////////////////////////////
    public function getSearchStatus() {
        $listApp = array();

        $execute = $this->queryUnit->getSelect('tbl_apps', "status=0");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listApp[] = $this->setCustomerValue($row);
            }
        }
        return $listApp;
    }
    //////////////////////////////////
    public function getAppByID($app_id) {
        $app = null;
        $execute = $this->queryUnit->getSelect('tbl_apps', "id='$app_id'");
        if (mysql_num_rows($execute) > 0) {
            $row = mysql_fetch_assoc($execute);
            $app = $this->setCustomerValue($row);
        }
        return $app;
    }
    ///////////////////////////////////
    public function insertApp(Admin_Models_tblApps $app){
        $execute= $this->queryUnit->getInsert('tbl_apps', $this->getColumnAndValue($app));
        if($execute){
            return TRUE;
        }
        return FALSE;
    }
    public function updateApp(Admin_Models_tblApps $app){
        $execute= $this->queryUnit->getUpdate('tbl_apps', $this->getColumnAndValue($app, TRUE), " id='".$app->getId()."'");
        if($execute){
            return TRUE;
        }
        return FALSE;
    }
    public function deleteApp($id){
        $exxcute= $this->queryUnit->getDelete('tbl_apps', "id= '$id'");
        if($exxcute){
            return TRUE;
        }
        return FALSE;
    }
    public function delListApp($listID){
        $condition = 'id IN (' . $listID . ')';
        $exxcute= $this->queryUnit->getDelete('tbl_apps', $condition);
        if($exxcute){
            return TRUE;
        }
        return FALSE;
    }
}
    